package gtkwire.widget.utils;

import java.io.*;
import gtkwire.*;
import gtkwire.widget.GtkWidget;

public class FileChooserMethods
{
	/**
	*Gets the filename for the currently selected file in the file selector. 
	*If multiple files are selected, one of the filenames will be returned at random.
	*If the file chooser is in folder mode, this function returns the selected folder.
	*/
	public static File getFile( GtkWidget widget )
	{
		GTKWireMessage answer = GTKWireApp.instance().
			sendCommandRequest( widget.getName(), widget.getWidgetType(), GTKWireCommandRequest.GET_FILENAME, null );
		return new File( (String) answer.getMessageObject() );
	}

	/**
	*Sets filename as the current filename for the file chooser, 
	*by changing to the file's parent folder and actually selecting the file in list. 
	*If the chooser is in GTK_FILE_CHOOSER_ACTION_SAVE mode, the file's base name will also appear in the dialog's file name entry.
	*/
	public static void setFile( GtkWidget widget, File f )
	{
		GTKWireApp.instance().sendCommand( widget.getName(), GTKWireCommand.SET_FILENAME, f.getAbsolutePath() );
	}


	/**
	* Sets curent folder in dialog.
	*/
	public static void setCurrentFolder( GtkWidget widget, String path )
	{
		GTKWireApp.instance().sendCommand( widget.getName(), GTKWireCommand.SET_CURRENT_FOLDER, path );
	}

}//end class